package org.jeecg.modules.wangyue.payment.alipay.config;

import com.alipay.api.*;
import lombok.Data;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Data
@Component("alipayConfigSandBox")
@Configuration
/**
 * 支付宝沙箱测试环境
 */
public class AlipayConfigSandBox {

    /**
     * 商户appid
     */
    private String appId = "9021000125629148";

    /**
     * 商户PID,卖家支付宝账号ID
     */
    private String sellerId = "2088721008277826";

    /**
     * 私钥 pkcs8格式的,rsc中的私钥
     */
    private String privateKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDJIRnMG8JUIPQEMyzOI2dbkZyyNmteItHzW6hDrov+PPRHWbBqLUmbxSARTmYrV4HGNaazLrHoBPLy87A1qANnoNj3I1nW68Y7HA+pEL3DqzsZauZiI8cLGlsyjjgs69/akcidF/+/5ic3hiFqH6FzA1i6eZ30LU//S+LaEW6w+WK54Zw8YReQI3JahvpaIeIbEsPrVyvLdkwPpG3qyiY7uHVEUEj4v0KPBWbV5JNT/ci5kOU4uw9LDI6v8WlJd//pp/kJ8lQHeBMobBUXrVr/SitFwoXByV6zdN6oDcuuaRqibk+oKtu9BhYtGAC1uwwIIRCopRTV+P5tIdDs8aNHAgMBAAECggEBAKghA2+bxNaOtWzNWqb28W+aSWKwGxCWCutjs0TgpCXizlDWqKIZOW79WdEduEqC2/jU4ITog89wU6bEDojL6gy2aKgu5OrELPE8g9rQI9FtUfntYqinP7wITDP2rv7eLkKHmyu25BOGUUIY3dXYmx2JrqIzB9cWCclfpkKkT+OfGXFpHMmwCRe+rjku5wtIRctXrwFtqqeVbnS6BMArrD96tWj57fT19+LC7SSz9dHrmvy6Iz9Hd05oIYPmc/dzquL4Y8DtMnkwFEaaZMRZLqW6JbdyX9LcGFlcwd3Szqogf/80nJ2/3tHaPyC/K8xjqimVWGPHwb/P2CL621GGAAECgYEA6BDyZiZy8D20oneBvARxRosCDoZTnxjFOKusgqWGX2Fr9+5v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Sy8g0/4NPthIkXG4po+BuRp18Cf0SH26uj+ricIO7VXhoTYEegBIcnlQtIGvG64vcr1qkNMXxSdlxHLZWBIaWlWIa58gHVg+OAH/xgeLNO+jVmoPnAzvZMpTRgQGqmO3Z+Lxm+l5d/ZXOmEKVVYGme8wy7e0la+Mg79VtQIDAQAB";

    /**
     * 请求网关地址
     */
    private String serverUrl = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";

    /**
     * 页面跳转同步通知（可以直接返回前端页面、或者通过后端进行跳转）
     */
    private String returnUrl = "http://localhost:8080/wangyue/app/payment/alipay/return";

    /**
     * 服务器异步通知
     */
    private String notifyUrl = " http://localhost:8080/wangyue/app/payment/alipay/notify";

    /**
     * 应用公钥证书
     */
    private String appCertPath = "C:/Users/31010/Desktop/alipay/alipaySandBox/appPublicCert.crt";
    //private String appCertPath = "/zhengshu/alipay/appCertPublicKey_2021004109628541.crt";

    /**
     * 支付宝公钥证书
     */
    private String alipayCertPath = "C:/Users/31010/Desktop/alipay/alipaySandBox/alipayPublicCert.crt";
    //private String alipayCertPath = "/zhenshu/alipay/alipayCertPublicKey_RSA2.crt";

    /**
     * 支付宝根证书
     */
    private String alipayRootCertPath = "C:/Users/31010/Desktop/alipay/alipaySandBox/alipayRootCert.crt";
    //private String alipayRootCertPath = "/zhenshu/alipay/alipayRootCert.crt";

    /**
     * 绝对地址
     */
    private String url = System.getProperty("user.dir");

    /**
     * 获得初始化的AlipayClient 公钥证书模式
     */
    public AlipayClient alipayClientSandBox() {
        try {
            // 获得初始化的AlipayClient 公钥证书模式
            CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
            certAlipayRequest.setServerUrl(this.serverUrl);
            certAlipayRequest.setAppId(this.appId);
            certAlipayRequest.setPrivateKey(this.privateKey);
            certAlipayRequest.setFormat(AlipayConstants.FORMAT_JSON);
            certAlipayRequest.setCharset(AlipayConstants.CHARSET_UTF8);
            certAlipayRequest.setSignType(AlipayConstants.SIGN_TYPE_RSA2);
            certAlipayRequest.setCertPath(this.appCertPath);
            certAlipayRequest.setAlipayPublicCertPath(this.alipayCertPath);
            certAlipayRequest.setRootCertPath(this.alipayRootCertPath);
            return new DefaultAlipayClient(certAlipayRequest);
        } catch (AlipayApiException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 获得初始化的AlipayClient 公钥不带证书模式
     */
    public AlipayClient alipayClientKeySandBox() {
        // 获得初始化的AlipayClient 公钥模式不带证书
        return new DefaultAlipayClient(serverUrl, appId, privateKey,
                AlipayConstants.FORMAT_JSON, AlipayConstants.CHARSET_UTF8,
                publicKey, AlipayConstants.SIGN_TYPE_RSA2);
    }

}

